/*
 * nextNode.cpp
 *
 *  Created on: Jul 8, 2012
 *      Author: jh238d
 */

#include "BSTNode.h"
#include <iostream>
using namespace std;

BSTNode2* find_next_node(BSTNode2 *node){
	if(node==NULL) return NULL;

	if(node->parent==NULL || node->right!=NULL){
		BSTNode *tmp = node->right;
		while(tmp->left!=NULL)
			tmp=tmp->left;
		return tmp;
	}
	else{
		BSTNode *tmp=node->parent;
		while(tmp!=NULL && tmp->left!=node){
			node=tmp;
			tmp=tmp->parent;
		}
		return tmp;
	}
}


